﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Data.SqlClient;



namespace XiangLin
{
    public partial class OrderForm : Form
    {
     

        public OrderForm()
        {
            InitializeComponent();
        }

        private void btnList_Click(object sender, EventArgs e)
        {

            string xmlFilePath = @"..\..\Order.xml";
            XmlReader reader = XmlReader.Create(xmlFilePath);
            double totalPrice = 0.0;

            reader.ReadToFollowing("Order");
            reader.MoveToFirstAttribute();
            txtOrder.Text += "Order ID: " + reader.Value + Environment.NewLine;

            reader.ReadToFollowing("Date");
            txtOrder.Text += "Date: " + reader.ReadElementContentAsString() + Environment.NewLine;

            reader.ReadToFollowing("BuyerID");
            txtOrder.Text += "BuyerID: " + reader.Value + Environment.NewLine + Environment.NewLine;

            //scan the file
            while (reader.ReadToFollowing("Item"))
            {
                //write item ID
                reader.MoveToFirstAttribute();
                txtOrder.Text += "Item ID: " + reader.Value + Environment.NewLine;

                //write Quantity
                reader.ReadToFollowing("Quantity");
                txtOrder.Text += "Quantity: " + reader.ReadElementContentAsInt() + Environment.NewLine;

                //write unit price
                reader.ReadToFollowing("UnitPrice");
                double itemPrice = reader.ReadElementContentAsDouble();
                txtOrder.Text += "Unit Price: " + itemPrice + Environment.NewLine;
                totalPrice += itemPrice;
                txtOrder.Text += Environment.NewLine;


            }

            txtOrder.Text += "Total: " + totalPrice;

        }

        private void btnMenu_Click(object sender, EventArgs e)
        {
            AllForm.mainPage.Show();
            this.Hide();
            txtOrder.Refresh();

        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            /*
            SqlConnection conn = new SqlConnection();
            SqlCommand comm = new SqlCommand();

            try
            {

                conn.ConnectionString = "data source=localhost;" + "initial catalog=SupplierDB;" + "integrated security=true";
                conn.Open();
                comm.Connection = conn;



            }

            */

        }


    }
}
